﻿using System;
using System.Collections.Generic;
using EmbeddedSharp.Core;

namespace EmbeddedSharp.Scripting.Function.IO {

    public enum EnvironmentPathType {
        MyDocuments = 0,
        System,
        CurrentDirectory,
        Desktop,
        ProgramFiles,
        CommonData
    }

    /// <summary>
    /// 
    /// </summary>
    public class SettingsNode : FuncNode {

        public SettingsNode()
            : base() {
            base.Value = "settings";
        }

        public override object Evaluate() {
            if (Parameters.Count < 1) {
                return "usage: settings(PathType)";
            }

            int t = Convert.ToInt32(Parameters[0].Evaluate());
            EnvironmentPathType type = (EnvironmentPathType)t;
            switch (type) {
                case EnvironmentPathType.MyDocuments:
                    return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    break;
                case EnvironmentPathType.System:
                    return Environment.GetFolderPath(Environment.SpecialFolder.System);
                    break;
                case EnvironmentPathType.CurrentDirectory:
                    return Environment.CurrentDirectory;
                    break;
                case EnvironmentPathType.Desktop:
                    return Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    break;
                case EnvironmentPathType.CommonData:
                    return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
                default:
                    break;
            }

            return string.Empty;
        }
    }
}
